package com.wcity.manage.web.wxShare;

import com.alibaba.fastjson.JSONObject;
import com.wcity.manage.common.utils.HttpUtil;
import com.wcity.manage.common.utils.NoncestrUitl;
import com.wcity.manage.common.utils.wx.PayUtil;
import com.wcity.manage.common.utils.wx.sign;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/22.
 */
@Controller
public class WxShareAct {


    @RequestMapping("wx_share")
    public ModelAndView wxShare () {
        System.out.println("进入");

        return new ModelAndView("wxShare/wxShare");
    }

    @RequestMapping ("get_config")
    @ResponseBody
    public Map<String,String> getConfig ( String url) {
        Map<String,String> map = new HashMap<>();
        String appID = "wxce9b87457ea4378a";
        String appsecret = "ad1bea94fcd7c3cfc115cfbb1b85587b";
        String strUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appID+"&secret="+appsecret;
        //调用http接口
        JSONObject jsonObject = JSONObject.parseObject(HttpUtil.sendGet(strUrl, "UTF-8")) ;

        String access_token = (String) jsonObject.get( "access_token" );

        String ticketUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+access_token+"&type=jsapi";
        //调用http接口，get方式
        JSONObject json = JSONObject.parseObject(HttpUtil.sendGet(ticketUrl, "UTF-8"));
        String jsapi_ticket = (String) json.get("ticket");
        return sign.sign(jsapi_ticket,url,appID);
    }
}
